using System;
using System.Collections.Generic;
using System.Text;
using BTV.Base;

namespace BTV.Bleb
{
    public class BlebSchedule : BTVSchedule
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
        bool isNextDay;
        private DateTime _day;

        public DateTime Day
        {
            get { return _day; }
            set { _day = value; }
        }
        private DateTime _end;

        public DateTime End
        {
            get { return _end; }
            set { _end = value; }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")]
        public override void SetStartTime(string time)
        {
            //format HHMM
            String hour = time.Substring(0, 2);
            String minute = time.Substring(2, 2);
            int h_int = Int32.Parse(hour);
            int m_int = Int32.Parse(minute);
            StartTime = new DateTime(_day.Year, _day.Month, _day.Day, h_int, m_int, 0);
            /*if (DateTime.Now != DateTime.UtcNow)
            {
                StartTime = StartTime.AddHours(1.0);
            }*/
            Duration = End - StartTime;
        }

        /*actually gets end time*/
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1725:ParameterNamesShouldMatchBaseDeclaration", MessageId = "0#")]
        public override void SetDuration(string time)
        {
            //format HHMM
            String hour = time.Substring(0, 2);
            String minute = time.Substring(2, 2);
            int h_int = Int32.Parse(hour);
            int m_int = Int32.Parse(minute);
            End = new DateTime(_day.Year, _day.Month, _day.Day, h_int, m_int, 0);
            Duration = End - StartTime;
        }

        public void SetNextDay()
        {
            isNextDay = true;
            _day = _day.AddDays(1.0);
        }

        public override string ToString()
        {
            String sMin = "" + StartTime.Minute;
            if (sMin.Length < 2)
            {
                sMin = "0" + sMin;
            }
            String eMin = "" + End.Minute;
            if (eMin.Length < 2)
            {
                eMin = "0" + eMin;
            }
            return Channel + " - " + StartTime.DayOfWeek.ToString() + " " + StartTime.Day + "/" + StartTime.Month + "/" + StartTime.Year + " - " + StartTime.Hour + ":" + sMin + " - " + End.Hour + ":" + eMin;
        }

        public override DateTime EndTime
        {
            get { return End; }
        }
    }
}
